local extension = Package("tshu_god")
extension.extensionName = "tshu"

Fk:loadTranslationTable{
  ["tshu_god"] = "天书.诸神",
  ["tshugod"] = "诸神",
}

local U = require "packages/utility/utility"


local kuafu = General(extension, "tshugod__kuafu","god",18)
local zhuri = fk.CreateTriggerSkill{
  name = "tshu__zhuri",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Start and player:hasSkill(self) 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|heart,diamond,spade,club",
    }
    room:judge(judge)
    if judge.card.color == Card.Red then
      local mark = player:getTableMark( "@tshu__zhuri-turn")
      table.insertIfNeed(mark, "red")
      room:setPlayerMark(player, "@tshu__zhuri-turn", mark)
    elseif judge.card.color == Card.Black then
      local mark = player:getTableMark( "@tshu__zhuri-turn")
      table.insertIfNeed(mark, "black")
      room:setPlayerMark(player, "@tshu__zhuri-turn", mark)
    end
    
  end,
  refresh_events = {fk.CardUsing,fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@tshu__zhuri-turn") and table.contains(player:getTableMark( "@tshu__zhuri-turn"), data.card:getColorString()) 
    and (event == fk.CardUsing and data.card.color == Card.Black or event == fk.CardUseFinished and data.card.color == Card.Red 
    and (player.room:getCardArea(data.card) == Card.Processing or player.room:getCardArea(data.card) == Card.PlayerEquip))
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if data.card.color == Card.Red then
      room:moveCards({
        ids = {data.card.id},
        from = player.id,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        skillName = self.name,
        drawPilePosition = -1,
      })
    elseif data.card.color == Card.Black then
      player:drawCards(1,self.name)
    end
  end
}
local yinjiang = fk.CreateTriggerSkill{
  name = "tshu__yinjiang",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
        if player.phase ~= Player.NotActive and player.phase == Player.Play then
          for _, move in ipairs(data) do
            return move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name and table.find(move.moveInfo, function (info)
              return info.fromArea == Card.DrawPile  end)
          end
        end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = player:drawCards(1,self.name,"bottom")
    card = Fk:getCardById(card[1])
    if card.color == Card.Red then
      local tar = {}
      for _, p in ipairs(room.alive_players) do
        if  (player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist")) then
          table.insert(tar,p)
        end
      end
      if #tar > 0 then
      room:damage({
        from = player,
        to = table.random(tar),
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
      end
    end
  end,
}
local lieben = fk.CreateTriggerSkill{
  name = "tshu__lieben",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      card = Fk:getCardById(room:getNCards(1,"bottom")[1]),
      who = player,
      reason = self.name,
      pattern = ".|.|heart,diamond",
    }
    room:judge(judge)
    if judge.card.color == Card.Red then
      if not data.extraUse then
        data.extraUse = true
        target:addCardUseHistory(data.card.trueName, -1)
      end
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
  end,
}
local shenqu = fk.CreateTriggerSkill{
  name = "tshu__shenqu",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self)  then
      self.cancel_cost = false
     for _ = 1, data.damage do
        if player.dead or self.cancel_cost then return end
        self:doCost(event, target, player, data)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      card = Fk:getCardById(room:getNCards(1,"bottom")[1]),
      who = player,
      reason = self.name,
      pattern = ".|.|heart,diamond",
    }
    room:judge(judge)
    if judge.card.color == Card.Red then
      if not player.dead then
        player:drawCards(1,self.name)
      end
      if data.from and not data.from.dead and not data.from:isNude() then
        local cards = data.from:getCardIds("he")
        room:moveCardTo(table.random(cards),Card.DiscardPile,player,fk.ReasonDiscard)
      end
    end
  end,
}
kuafu:addSkill(zhuri)
kuafu:addSkill(yinjiang)
kuafu:addSkill(lieben)
kuafu:addSkill(shenqu)
kuafu.hidden = true
Fk:loadTranslationTable{
  ["tshugod__kuafu"] = "夸父",

  ["tshu__zhuri"] = "逐日",
  [":tshu__zhuri"] = "锁定技，准备阶段，你进行判定，若判定结果为:红色，本回合你使用红色牌结算完毕后，将该牌放置于牌堆底；黑色，本回合你使用黑色牌时，你摸一张牌。",
  ["tshu__yinjiang"] = "饮江",
  [":tshu__yinjiang"] = "锁定技，当你在出牌阶段摸牌后，额外从牌堆底获得一张牌，若该牌是红色，则随机对一名敌方角色造成1点伤害。",
  ["tshu__lieben"] = "烈奔",
  [":tshu__lieben"] = "锁定技，当你使用【杀】时，使用堆底的牌进行判定：若结果为红色，则此杀不计入出牌阶段使用次数且伤害+1。",
  ["tshu__shenqu"] = "神躯",
  [":tshu__shenqu"] = "锁定技，当你受到1点伤害后，使用牌堆底的牌进行判定：若结果为红色，你摸一张牌，伤害来源随机弃置一张牌。",
  ["#tshu__shenqu"] = "神躯：你需弃置一张牌。",
  ["@tshu__zhuri-turn"] = "逐日",

  ["$tshu__zhuri"] = "狂飙八万里，逐日九重天！",
  ["$tshu__yinjiang"] = "大江三千顷，豪饮一息间。",
  ["$tshu__lieben"] = "奔雷析紫电，池鱼断清风。",
  ["$tshu__shenqu"] = "神躯天成，伤之必逝。",
  ["~tshugod__kuafu"] = "大泽江河..",
}


local xuannv = General(extension, "tshugod__xuannv","god",18,18,General.Female)
local dishi = fk.CreateTriggerSkill{
  name = "tshu__dishi",
  anim_type = "control",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(self) and (data.card:isCommonTrick() or data.card.trueName == "slash") and data.firstTarget then
      if #AimGroup:getAllTargets(data.tos) == 1 then
        local targets = player.room:getUseExtraTargets( data, true, true)
        local origin_targets = U.getActualUseTargets(room, data, event)
        if #origin_targets > 1 then
            table.insertTable(targets, origin_targets)
        end
        if (data.card.trueName == "slash" or data.card.is_damage_card or data.card.name == "dismantlement" or data.card.name == "snatch" or data.card.name == "iron_chain") then
          for _, p in ipairs(room.alive_players) do
              if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist")))  and table.contains(targets,p.id) then
                return true
              end
          end
        else
          for _, p in ipairs(room.alive_players) do
            if ((player.role == "rebel" and p.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role == "lord" or p.role == "loyalist")))  and table.contains(targets,p.id) then
              return true
            end
        end
        end
      elseif #AimGroup:getAllTargets(data.tos) > 1 then
        local origin_targets = U.getActualUseTargets(room, data, event)
        if (data.card.trueName == "slash" or data.card.is_damage_card or data.card.name == "dismantlement" or data.card.name == "snatch" or data.card.name == "iron_chain") then
          for _, pid in ipairs(origin_targets) do
            local p = room:getPlayerById(pid)
              if (player.role == "rebel" and p.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role == "lord" or p.role == "loyalist"))  then
                return true
              end
          end
        else
          for _, pid in ipairs(origin_targets) do
            local p = room:getPlayerById(pid)
              if (player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))  then
                return true
              end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local over = false
    if #AimGroup:getAllTargets(data.tos) == 1 then
      local targets = player.room:getUseExtraTargets( data, true, true)
      local origin_targets = U.getActualUseTargets(room, data, event)
      if #origin_targets > 1 then
          table.insertTable(targets, origin_targets)
      end
      if (data.card.trueName == "slash" or data.card.is_damage_card or data.card.name == "dismantlement" or data.card.name == "snatch" or data.card.name == "iron_chain") then
        for _, p in ipairs(room.alive_players) do
          if over then break end
            if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist")))  and table.contains(targets,p.id) then
              player.room:doIndicate(player.id, {p.id})
              AimGroup:addTargets(player.room, data,p.id)
              over = true
            end
        end
      else
        for _, p in ipairs(room.alive_players) do
          if over then break end
          if ((player.role == "rebel" and p.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role == "lord" or p.role == "loyalist")))  and table.contains(targets,p.id) then
            player.room:doIndicate(player.id, {p.id})
            AimGroup:addTargets(player.room, data,p.id)
          end
      end
      end
    elseif #AimGroup:getAllTargets(data.tos) > 1 then
      local origin_targets = U.getActualUseTargets(room, data, event)
      if (data.card.trueName == "slash" or data.card.is_damage_card or data.card.name == "dismantlement" or data.card.name == "snatch" or data.card.name == "iron_chain") then
        for _, pid in ipairs(origin_targets) do
          if over then break end
          local p = room:getPlayerById(pid)
            if ((player.role == "rebel" and p.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role == "lord" or p.role == "loyalist")))  then
              player.room:doIndicate(player.id, {p.id})
              AimGroup:cancelTarget(data,p.id)
              over = true
            end
        end
      else
        for _, pid in ipairs(origin_targets) do
          if over then break end
          local p = room:getPlayerById(pid)
            if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist")))  then
              player.room:doIndicate(player.id, {p.id})
              AimGroup:cancelTarget(data,p.id)
              over = true
            end
        end
      end
    end
  end,
}
local jiutian = fk.CreateTriggerSkill{
  name = "tshu__jiutian",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if target == player and player:hasSkill(self) and player.phase == Player.Start then
      for _, p in ipairs(room.alive_players) do
        if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) and not p:isKongcheng() then
          local cids = p.player_cards[Player.Hand]
          local suits = {}
          for _, cid in ipairs(cids) do
            local c = Fk:getCardById(cid)
            if not table.contains(suits,c.suit) then
              table.insertIfNeed(suits,c.suit)
            end
          end
          if #suits > 2 then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local getcards = {}
    local getsuits = {}
    local damage = true
    local targets = {}
    for _, p in ipairs(room.alive_players) do
      if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) and not p:isKongcheng() then
        local cids = p.player_cards[Player.Hand]
        local suits = {}
        for _, cid in ipairs(cids) do
          local c = Fk:getCardById(cid)
          if not table.contains(suits,c.suit) then
            table.insertIfNeed(suits,c.suit)
          end
        end
        if #suits > 2 then
          table.insertIfNeed(targets,p)
          local get = false
          for _, cid in ipairs(cids) do
            if get then break end
            local c = Fk:getCardById(cid)
            if not table.contains(getsuits,c.suit) then
              table.insertIfNeed(getsuits,c.suit)
              table.insertIfNeed(getcards,c.id)
              get = true
            end
          end
          if not get then
            table.insertIfNeed(getcards,table.random(cids,1))
            damage = false
          end
        end
      end
    end
    if #getcards > 0 then
      room:moveCardTo(getcards,player.Hand,player,fk.ReasonPrey)
      if damage then
        player:showCards(getcards)
        for _, p in ipairs(targets) do
          room:damage({
            from = player,
            to = p,
            damage = 1,
            damageType = fk.NormalDamage,
            skillName = self.name,
          })
        end
      end
    end
  end,
}

local xuanlie = fk.CreateTriggerSkill{
  name = "tshu__xuanlie",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd,fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      if player:hasSkill(self) then
          if player.phase ~= Player.NotActive  then
            for _, move in ipairs(data) do
              return move.to == player.id and move.from and  ((player.role == "rebel" and player.room:getPlayerById(move.from).role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (player.room:getPlayerById(move.from).role ~= "lord" and player.room:getPlayerById(move.from).role ~= "loyalist"))) and move.toArea == Player.Hand and player.room:getPlayerById(move.from):getMark("tshu__xuanlie-turn") == 0
            end
          end
      end
    elseif event == fk.TurnEnd and  target == player and player:hasSkill(self)then
      for _, p in ipairs(player.room.alive_players) do
        if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) and p:getMark("tshu__xuanlie-turn") > 0 then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if ((player.role == "rebel" and player.room:getPlayerById(move.from).role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (player.room:getPlayerById(move.from).role ~= "lord" and player.room:getPlayerById(move.from).role ~= "loyalist")))   then
          room:setPlayerMark(player.room:getPlayerById(move.from),"tshu__xuanlie-turn",1)
        end
      end
    elseif event == fk.TurnEnd then
      for _, p in ipairs(player.room.alive_players) do
        if player.dead then break end
        if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) and p:getMark("tshu__xuanlie-turn") > 0 then
          room:damage({
            from = player,
            to = p,
            damage = 1,
            damageType = fk.NormalDamage,
            skillName = self.name,
          })
        end
      end
    end
  end,
}
xuannv:addSkill(dishi)
xuannv:addSkill(jiutian)
xuannv:addSkill(xuanlie)
xuannv:addSkill("tshu__shenqu")
xuannv.hidden = true
Fk:loadTranslationTable{
  ["tshugod__xuannv"] = "玄女",

  ["tshu__dishi"] = "帝师",
  [":tshu__dishi"] = "当一名角色使用【杀】或普通锦牌指定目标时，若目标数:为1，你可以为其增加目标；大于1，你可以为其减少目标。",
  ["tshu__jiutian"] = "九天",
  [":tshu__jiutian"] = "锁定技，准备阶段，若敌方角色有超过两种不同花色的手牌，则你获得其一张手牌。若你以此法获得的所有牌的花色均不同，则对所有你以此法获得其牌的敌方角色造成1点伤害。",
  ["tshu__xuanlie"] = "玄烈",
  [":tshu__xuanlie"] = "锁定技，回合结束时，对所有本回合你获得过其牌的敌方角色依次造成1点伤害。",

  ["$tshu__dishi"] = "慈航化众生，司南引轩辕。",
  ["$tshu__jiutian"] = "天上九宫十二城，仙云袅袅授长生。",
  ["$tshu__xuanlie"] = "碧霄一鹤引霞至，玄女箜篌九天来。",
  ["$tshu__shenqu_tshugod__xuannv"] = "宝体天赐，触之必溃。",
  ["~tshugod__xuannv"] = "世间何来两全法,不负仙侣不负卿。",
}

local shaohao = General(extension, "tshugod__shaohao","god",18)
local shenen = fk.CreateTriggerSkill{
  name = "tshu__shenen",
  anim_type = "control",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.DamageFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if not data.dealtRecorderId then return true end
      if data.extra_data and data.extra_data.shenen_maxDamage then
        if data.damage == 0 and  data.extra_data.shenen_maxDamage > 0 then
          if data.extra_data.shenen_ss and data.extra_data.shenen_zc then
            local p = data.extra_data.shenen_ss
            local p2 = data.extra_data.shenen_zc
            if ((player.role == "rebel" and p.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role == "lord" or p.role == "loyalist"))) 
            and ((player.role == "rebel" and p2.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p2.role ~= "lord" and p2.role ~= "loyalist"))) then
              return not ( data.skillName and data.skillName == self.name)
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local p = data.extra_data.shenen_ss
    local p2 = data.extra_data.shenen_zc
    if p and ((player.role == "rebel" and p.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role == "lord" or p.role == "loyalist"))) 
    and p2 and ((player.role == "rebel" and p2.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p2.role ~= "lord" and p2.role ~= "loyalist")))then
      player.room:notifySkillInvoked(player,self.name,"offensive")
    player.room:damage({
      from = data.extra_data.shenen_ss,
      to = data.extra_data.shenen_zc,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name,
    })
    end
  end,

  refresh_events = {fk.AfterSkillEffect, fk.SkillEffect},
  can_refresh = function (self, event, target, player, data)
    return player == player.room.players[1]
  end,
  on_refresh = function(self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.Damage, true)
    
    if e then
      local dat = e.data[1]
      dat.extra_data = dat.extra_data or {}
      dat.extra_data.shenen_maxDamage = dat.extra_data.shenen_maxDamage or 0
      dat.extra_data.shenen_maxDamage = math.max(dat.damage, dat.extra_data.shenen_maxDamage)
      dat.extra_data.shenen_ss = dat.to
      dat.extra_data.shenen_zc = dat.from
    end
  end,
}
local shenen_trigger = fk.CreateTriggerSkill{
  name = "#shenen_trigger",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target and player:hasSkill(self) and ((player.role == "rebel" and target.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role == "lord" or target.role == "loyalist"))) and data.damageType == fk.NormalDamage
  end,
  on_use = function(self, event, target, player, data)
    data.damageType = table.random({fk.FireDamage,fk.ThunderDamage})
  end,
}
local shenen_distance = fk.CreateDistanceSkill{
  name = "#tshu__shenen_distance",
  correct_func = function(self, from, to)
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p:hasSkill(self) and ((from.role == "rebel" and p.role == from.role) or ((from.role == "lord" or from.role == "loyalist") and (p.role == "lord" or p.role == "loyalist"))) then
        return -999
      end
    end
  end,
}
local shenen_maxcards = fk.CreateMaxCardsSkill{
  name = "#tshu__shenen_maxcards",
  correct_func = function(self, player)
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if p:hasSkill(self) and ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
          return 1
        end
      end
  end,
}
local baiyi = fk.CreateTriggerSkill{
  name = "tshu__baiyi",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards,fk.RoundStart,fk.DamageInflicted,fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local r = room:getTag("RoundCount")
    if (r//10)%2 == 0 then
      if event == fk.DrawNCards then
        return target and player:hasSkill(self) and ((player.role == "rebel" and target.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role ~= "lord" and target.role ~= "loyalist"))) 
      elseif event == fk.RoundStart then
        return  player:hasSkill(self) and r%10 == 5
      elseif event == fk.DamageInflicted then
        return target and player:hasSkill(self) and ((player.role == "rebel" and target.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role == "lord" or target.role == "loyalist"))) and data.damageType == fk.ThunderDamage
      elseif event == fk.DamageCaused then
        return target and player:hasSkill(self) and ((player.role == "rebel" and target.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role == "lord" or target.role == "loyalist")))  and data.damageType == fk.FireDamage
      end
    else
      if event == fk.DrawNCards then
        return target and player:hasSkill(self) and ((player.role == "rebel" and target.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role == "lord" or target.role == "loyalist"))) 
      elseif event == fk.RoundStart then
        return  player:hasSkill(self) and r%10 == 5
      elseif event == fk.DamageInflicted then
        return target and player:hasSkill(self) and ((player.role == "rebel" and target.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role == "lord" or target.role == "loyalist"))) and data.damageType == fk.FireDamage
      elseif event == fk.DamageCaused then
        return target and player:hasSkill(self) and ((player.role == "rebel" and target.role == player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role == "lord" or target.role == "loyalist")))  and data.damageType == fk.ThunderDamage
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local r = room:getTag("RoundCount")
    if (r//10)%2 == 0 then
      if event == fk.DrawNCards then
        data.n = data.n - 1
      elseif event == fk.RoundStart then
      for _, p in ipairs(room.alive_players) do
        if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
          room:damage({
            from = player,
            to = p,
            damage = 1,
            damageType = fk.FireDamage,
            skillName = self.name,
          })
        end
      end
      end
    else
      if event == fk.DrawNCards then
        data.n = data.n + 1
      elseif event == fk.RoundStart then
      for _, p in ipairs(room.alive_players) do
        if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
          room:damage({
            from = player,
            to = p,
            damage = 1,
            damageType = fk.ThunderDamage,
            skillName = self.name,
          })
        end
      end
      end
    end
    if event == fk.DamageInflicted then
      return true 
    elseif event == fk.DamageCaused then
      data.damage = data.damage + 1
    end
  end,
}
shenen:addRelatedSkill(shenen_trigger)
shenen:addRelatedSkill(shenen_distance)
shenen:addRelatedSkill(shenen_maxcards)
shaohao:addSkill(shenen)
shaohao:addSkill(baiyi)
shaohao.hidden = true
Fk:loadTranslationTable{
  ["tshugod__shaohao"] = "少昊",

  ["tshu__shenen"] = "神恩",
  [":tshu__shenen"] = "锁定技，己方角色使用牌无距离限制且造成的普通伤害转化为随机属性伤害。敌方角色手牌上限+1。当己方角色受到来自敌方角色的伤害被防止时，其对原伤害来源造成一点伤害。",
  ["tshu__baiyi"] = "白仪",
  [":tshu__baiyi"] = "锁定技，<br>若当前轮次十位数为偶数，敌方角色摸牌阶段少摸一张牌；己方造成火焰伤害时伤害+1且防止受到的雷电伤害；当轮次个位数为5的轮次开始时，对所有敌方角色各造成一点火焰伤害。"..
  "<br>若当前轮次十位数为奇数，己方角色的摸牌阶段多摸一张牌；己方造成雷电伤害时伤害+1且防止受到的火焰伤害；当轮次个位数为5的轮次开始时，对所有敌方角色各造成一点雷电伤害。",

  ["#shenen_trigger"] = "神恩",
}


local hanba = General(extension, "tshugod__hanba","god",18,18,General.Female)
local fenshi = fk.CreateTriggerSkill{
  name = "tshu__fenshi",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and player:getHandcardNum() ~= player.hp
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getHandcardNum() < player.hp then
      player:drawCards(player.hp - player:getHandcardNum(),self.name)
    elseif player:getHandcardNum() > player.hp then
      local n = player:getHandcardNum() - player.hp
      local tar = {}
      for _, p in ipairs(room.alive_players) do
        if ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
          table.insertIfNeed(tar,p)
        end
      end
      local m = #tar
      local dam = {}
      for i = 1, m, 1 do
        if i == m then
          dam[i] = n
        else
          dam[i] = math.random(0,n)
          n = n - dam[i]
        end
      end
      for i = 1,m ,1 do
        room:damage({
          from = player,
          to = tar[i],
          damage = dam[i],
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end,
}
local zhiri = fk.CreateTriggerSkill{
  name = "tshu__zhiri",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and ((player.role == "rebel" and target.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role ~= "lord" and target.role ~= "loyalist"))) and data.card and data.card.color == Card.Red and data.card.type == Card.TypeTrick and data.firstTarget
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player.dead then
      player:drawCards(3,self.name)
    end
  end,
}
local xinji = fk.CreateTriggerSkill{
  name = "tshu__xinji",
  anim_type = "support",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.phase == Player.NotActive then
      local room = player.room
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonDiscard  then
          if move.from  then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return move.from == player.id and not player.dead and ((player.role == "rebel" and player.room.current.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (player.room.current.role ~= "lord" and player.room.current.role ~= "loyalist")))
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage({
      from = player,
      to = player.room.current,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name,
    })
  end,
}
hanba:addSkill(fenshi)
hanba:addSkill(zhiri)
hanba:addSkill(xinji)
hanba.hidden = true
Fk:loadTranslationTable{
  ["tshugod__hanba"] = "旱魃",

  ["tshu__fenshi"] = "焚世",
  [":tshu__fenshi"] = "锁定技，准备阶段，若你的手牌数小于体力值，则将手牌摸至于体力值相等；若你的手牌数大于体力值，则你对敌方角色造成共计X点伤害，点数随机分配（X为手牌数减体力值）。",
  ["tshu__zhiri"] = "炙日",
  [":tshu__zhiri"] = "锁定技，当敌方角色使用红色锦囊牌指定目标后，你摸三张牌。",
  ["tshu__xinji"] = "心悸",
  [":tshu__xinji"] = "锁定技，当你于回合外因弃置而失去手牌时，若当前回合角色是敌方角色，你对其造成1点伤害。",

  ["$tshu__fenshi1"] = "业火燎原，焚天灭地。",
  ["$tshu__fenshi2"] = "骄阳似火，万物无生。",
  ["$tshu__zhiri1"] = "你以为，这样就已经结束了？",
  ["$tshu__zhiri2"] = "好舒服，这太阳的力量。",
  ["$tshu__xinji1"] = "人人心中，都有一团欲望之火。",
  ["$tshu__xinji2"] = "让心中之火，慢慢吞噬你吧！哈哈哈哈~",
  ["~tshugod__hanba"] = "应龙，是你在呼唤我吗？",
}

local caoe = General(extension, "tshugod__caoe","god",18,18,General.Female)
local shoujiang = fk.CreateTriggerSkill{
  name = "tshu__shoujiang",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self)  then
      return  data.damage > 1 and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      data.damage = 1
      if not player.dead then
        local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick",3,"allPiles")
      if #cards > 0 then
      room:moveCards({
        ids = cards,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        proposer = player.id,
        skillName = self.name,
      })
      end
      end
  end,
}
local luoshen = fk.CreateTriggerSkill{
  name = "tshu__luoshen",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Start and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    while true do
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|spade,club",
      }
      room:judge(judge)
      local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick",2,"allPiles")
      if #cards > 0 then
      room:moveCards({
        ids = cards,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        proposer = player.id,
        skillName = self.name,
      })
      room:setCardMark(Fk:getCardById(cards[1]), "@@tshu__luoshen-inhand-turn", 1)
      room:setCardMark(Fk:getCardById(cards[2]), "@@tshu__luoshen-inhand-turn", 1)
      end
      if judge.card.color ~= Card.Black then
        break
      end
      if not room:askForSkillInvoke(player, self.name) then
        break
      end
    end
  end,
}
local luoshen_max = fk.CreateMaxCardsSkill{
  name = "#tshu__luoshen_max",
  exclude_from = function(self, player, card)
    return card:getMark("@@tshu__luoshen-inhand-turn") > 0
  end,
}
luoshen:addRelatedSkill(luoshen_max)
caoe:addSkill(shoujiang)
caoe:addSkill("mashu")
caoe:addSkill(luoshen)
caoe:addSkill("ex__biyue")
caoe:addSkill("jizhi")
caoe:addSkill("guose")
caoe.hidden = true
Fk:loadTranslationTable{
  ["tshugod__caoe"] = "曹娥",

  ["tshu__shoujiang"] = "守江",
  [":tshu__shoujiang"] = "锁定技，每回合限一次，当你受到伤害时，若该伤害大于1点，则此伤害变为1点（防止多余的伤害），然后你从牌堆或弃牌堆获得三张锦囊牌。",
  ["tshu__luoshen"] = "洛神",
  [":tshu__luoshen"] = "准备阶段开始时，你可以进行判定，然后从牌堆或弃牌堆中获得两张锦囊牌，若判定结果为黑，则你可重复此流程。你以此法获得的牌在本回合不计入手牌上限。",
  ["@@tshu__luoshen-inhand-turn"] = "洛神",

  ["$tshu__shoujiang"] = "沿江号哭悲，昼夜不绝声。",
  ["$ex__biyue_tshugod__caoe"] = "月昏星暗，何人爱怜。",
  ["$tshu__luoshen"] = "清波川洛，江涛无声。",
  ["$jizhi_tshugod__caoe"] = "结草衔环，孝感动天。",
  ["$guose_tshugod__caoe"] = "娇花碧玉，明眸齿白。",
  ["~tshugod__caoe"] = "父亲，这江水好冷~",
}

local taoshen = General(extension, "tshugod__taoshen","god",18)
local nutao = fk.CreateTriggerSkill{
  name = "tshu__nutao",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TargetSpecified then
        return data.card.type == Card.TypeTrick and data.firstTarget and
          table.find(AimGroup:getAllTargets(data.tos), function(id) return id ~= player.id end)
      else
        return player.phase == Player.Play and data.damageType == fk.ThunderDamage
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local targets = table.filter(AimGroup:getAllTargets(data.tos), function(id)
        return id ~= player.id and not room:getPlayerById(id).dead end)
      local to = room:getPlayerById(table.random(targets))
      room:doIndicate(player.id, {to.id})
      room:damage{
        from = player,
        to = to,
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
    else
      room:addPlayerMark(player, "@tshu__nutao-phase", 1)
    end
  end,
}
local nutao_targetmod = fk.CreateTargetModSkill{
  name = "#tshu__nutao_targetmod",
  residue_func = function(self, player, skill, scope, card, to)
    if card and card.trueName == "slash" and player:getMark("@tshu__nutao-phase") > 0 and scope == Player.HistoryPhase then
      return player:getMark("@tshu__nutao-phase")
    end
  end,
}
local xiongzi = fk.CreateTriggerSkill{
  name = "tshu__xiongzi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self)  then
      return  true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #room.alive_players
    if table.every(room.alive_players, function(p) return p:getHandcardNum() >= player:getHandcardNum() end) then
      n = 2*n
    end
    data.n = data.n +  n
  end,
}
nutao:addRelatedSkill(nutao_targetmod)
taoshen:addSkill(nutao)
taoshen:addSkill(xiongzi)
taoshen:addSkill("mashu")
taoshen:addSkill("longdan")
taoshen:addSkill("wushuang")
taoshen.hidden = true
Fk:loadTranslationTable{
  ["tshugod__taoshen"] = "涛神",

  ["tshu__nutao"] = "怒涛",
  [":tshu__nutao"] = "锁定技，当你使用锦囊牌指定其他角色为目标时，随机对其中一个目标造成一点雷电伤害；<br>你于出牌阶段每造成一点雷电伤害，此阶段出【杀】次数+1。",
  ["@tshu__nutao-phase"] = "怒涛",
  ["tshu__xiongzi"] = "雄姿",
  [":tshu__xiongzi"] = "锁定技，摸牌阶段，你多摸X张牌，如果手牌数为全场最少，则改为多摸2*X张牌。(X为场上存活人数)",


  ["$tshu__nutao"] = "无序怒涛，奔流不灭。",
  ["$longdan_tshugod__taoshen"] = "波澜逆转，攻守皆可。",
  ["$wushuang_tshugod__taoshen"] = " 波涛怒天，神力无边。",
  ["$tshu__xiongzi"] = "智勇深沉，一世之雄。",
  ["~tshugod__taoshen"] = "马革裹尸，身沉江心。",
}

local hebo = General(extension, "tshugod__hebo","god",18)
local zhangchuan = fk.CreateTriggerSkill{
  name = "tshu__zhangchuan",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {"fk.chuan"},
  can_trigger = function(self, event, target, player, data)
   if event == "fk.chuan" then
      local n = player:getMark("@tshu__chuan")
      return player:hasSkill(self) and ( n%4 == 0 or n%5 == 0 or n > 100 )
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == "fk.chuan" then
      local n = player:getMark("@tshu__chuan")
      if n%4 == 0 then
        if not player.dead then
          player:drawCards(1,self.name)
        end
      end
      if n%5 == 0 then
        local targets = {}
        for _, p in ipairs(room.alive_players) do
          if not p:isNude() and p.role ~= "renegade" and ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
            table.insertIfNeed(targets,p)
          end
        end
        if #targets > 0 then
            local cards = table.random(targets):getCardIds("he")
            room:moveCardTo(table.random(cards),Card.DiscardPile,player,fk.ReasonDiscard)
        end
      end
      if n > 100 then
        room:setPlayerMark(player,"@tshu__chuan",0)
        local cards = {}
        for _, p in ipairs(room:getOtherPlayers(player)) do
          if not p:isKongcheng() then
            table.insertTable(cards,p:getCardIds("h"))
          end
        end
        if #cards > 0 then
          if player:getHandcardNum() < 100 then
            local cards2 = table.random(cards,(100 - player:getHandcardNum()))
            room:moveCardTo(cards2,Card.PlayerHand,player,fk.ReasonPrey,self.name)
            cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) ~= player end)
            room:moveCardTo(cards,Card.DiscardPile,player,fk.ReasonDiscard,self.name)
          else
            room:moveCardTo(cards,Card.DiscardPile,player,fk.ReasonDiscard,self.name)
          end
        end
      end
    end
  end,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if event == fk.AfterCardsMove and player:hasSkill(self) and not player.dead then
      local n = 0
        for _, move in ipairs(data) do
          for _, info in ipairs(move.moveInfo) do
            if  move.toArea == Card.DiscardPile then
              n = n + 1
            end
          end
        end
      self.cost_data = n
      return n > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for i = 1, self.cost_data, 1 do
        room:addPlayerMark(player,"@tshu__chuan",1)
        room.logic:trigger("fk.chuan", player, { name = "@tshu__chuan", num = 1})
      end
    end
  end,
}
local zunqing = fk.CreateTriggerSkill{
  name = "tshu__zunqing",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused,fk.PreHpRecover},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and ((event == fk.DamageCaused and player:getMark("@tshu__chuan") >= 20)or (event == fk.PreHpRecover and player:getMark("@tshu__chuan") >= 40))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"offensive")
      data.damage = data.damage + 1
    elseif event == fk.PreHpRecover then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"support")
      data.num = data.num + 2
    end
  end,
}
local xiaozi = fk.CreateTriggerSkill{
  name = "tshu__xiaozi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self)  then
      return  player:getMark("@tshu__chuan") >= 10
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getMark("@tshu__chuan")
    n = (n%100)//10
    data.n = data.n +  n
  end,
}
hebo:addSkill(zhangchuan)
hebo:addSkill(zunqing)
hebo:addSkill(xiaozi)
hebo.hidden = true
Fk:loadTranslationTable{
  ["tshugod__hebo"] = "河伯",

  ["tshu__zhangchuan"] = "掌川",
  [":tshu__zhangchuan"] = "锁定技，每当一张牌进入弃牌堆后，你获得一个“川”标记；当“川”标记数达到4的倍数时，你摸一张牌；当“川”标记数达到5的倍数时，你随机弃置一名敌方角色的牌；当“川”标记数超过100时，你弃置所有“川”标记，然后你获得所有其他角色手牌(你最多以此法让手牌获得至为100张，超过100张则改为置入弃牌堆)。",
  ["tshu__zunqing"] = "尊清",
  [":tshu__zunqing"] = "锁定技，你的“川”标记数达到20时，你造成伤害值+1；你的“川”标记数达到40时，你回复体力值+2。",
  ["tshu__xiaozi"] = "潇姿",
  [":tshu__xiaozi"] = "锁定技，你摸牌阶段多摸X张牌（X为你的“川”标记数的十位数）。",
  ["@tshu__chuan"] = "川",


  ["$tshu__zhangchuan"] = "本神覆手之间，可倾天下之江河湖海。",
  ["$tshu__zunqing"] = "尊太上三清，江海盈而则国成。",
  ["$tshu__xiaozi"] = "人间草莽之辈，安能识得仙人之风骨？",
  ["~tshugod__hebo"] = "我本人间逍遥客，奈何漠水寒千秋。",
}

local yuershen = General(extension, "tshugod__yuershen","god",18)
local wanshe = fk.CreateTriggerSkill{
  name = "tshu__wanshe",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing,fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target and  player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("@tshu__wanshe") ~= 0 and data.card:getTypeString() ~= player:getMark("@tshu__wanshe") then
        player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"control")
      local targets = {}
        for _, p in ipairs(room.alive_players) do
          if not p:isNude() and p.role ~= "renegade" and ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
            table.insertIfNeed(targets,p)
          end
        end
        if #targets > 0 then
            local cards = table.random(targets):getCardIds("he")
            room:moveCardTo(table.random(cards),Card.DiscardPile,player,fk.ReasonDiscard)
        end
    end
    if data.card:getTypeString() ~= "notype" then room:setPlayerMark(player, "@tshu__wanshe", data.card:getTypeString()) end
  end,
}
local shanling = fk.CreateTriggerSkill{
  name = "tshu__shanling",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.damage > 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|heart,diamond,spade,club",
    }
    room:judge(judge)
    if judge.card.color == Card.Red and player:isWounded() then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    elseif judge.card.color == Card.Black and data.from then
      room:damage({
        from = player,
        to = data.from,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}
local xuntan = fk.CreateTriggerSkill{
  name = "tshu__xuntan",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.HpRecover,"fk.xuntan"},
  can_trigger = function(self, event, target, player, data)
  if player.general ~= "tshugod__yuershen" then return end
    if event == fk.HpRecover then
      return  target and player:hasSkill(self.name) 
    elseif event == "fk.xuntan" then
      if target == player and player:hasSkill(self) and player:getMark("tshu__xuntan") >= 5 then
        for _, p in ipairs(player.room.alive_players) do
          if p.hp < 1 then
            return false
          end
        end
        return  true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.HpRecover then
      room:addPlayerMark(player,"tshu__xuntan",data.num)
      room.logic:trigger("fk.xuntan", player, { name = "tshu__xuntan", num = data.num})
    elseif event == "fk.xuntan" then
      if player.hp < 1 then return end
        player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"special")
        room:setPlayerMark(player,"tshu__xuntan",0)
        player:gainAnExtraTurn(true)
        room.logic:breakTurn()
    end
  end,
}
yuershen:addSkill(wanshe)
yuershen:addSkill(shanling)
yuershen:addSkill(xuntan)
yuershen.hidden = true
Fk:loadTranslationTable{
  ["tshugod__yuershen"] = "于儿神",

  ["tshu__wanshe"] = "挽蛇",
  [":tshu__wanshe"] = "锁定技，当有角色使用或打出一张牌时，若此牌与上一张使用或打出的牌类型不同，你随机弃置敌方角色的一张牌。",
  ["tshu__shanling"] = "闪鳞",
  [":tshu__shanling"] = "锁定技，当你受到大于1点的伤害后，你进行判定：若为红，你回复一点体力；若为黑，伤害来源受到一点伤害。(仅对于儿神生效)",
  ["tshu__xuntan"] = "巡潭",
  [":tshu__xuntan"] = "锁定技，每当场上角色累计回复5点体力时，你立即获得一个额外回合。",
  ["@tshu__wanshe"] = "挽蛇",
  ["@tshu__xuntan"] = "巡潭",



  ["$tshu__wanshe"] = "灵蛇待捕，欲以诸君之身为饲饵。",
  ["$tshu__shanling"] = "",
  ["$tshu__xuntan"] = "江海相连，居小潭可辩天下之水文。",
  ["~tshugod__yuershen"] = "魂陨江海，所愿皆覆浪涛",
}

local yanwang = General(extension, "tshugod__yanluowang","god",18)
local tiemian = fk.CreateTriggerSkill{
  name = "tshu__tiemian",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" and data.card.color and data.card.color == Card.Red and math.random(1,4) <= 3
  end,
  on_use = function(self, event, target, player, data)
      table.insertIfNeed(data.nullifiedTargets, player.id)
      return true
  end,
}
local difu = fk.CreateTriggerSkill{
  name = "tshu__difu",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return  player:hasSkill(self.name) and target:getHandcardNum() > target.hp and target.phase == Player.Play and ((player.role == "rebel" and target.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (target.role ~= "lord" and target.role ~= "loyalist")))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = target:getHandcardNum() - target.hp
    if target:getHandcardNum() >= 50 then
      local cards = target:getCardIds("h")
      room:moveCardTo(table.random(cards,n),Card.DiscardPile,player,fk.ReasonDiscard)
    else
      room:askForDiscard(target,n,n,false,self.name,false)
    end
  end,
}
local zhennu = fk.CreateTriggerSkill{
  name = "tshu__zhennu",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
     return  target == player and player:hasSkill(self.name) and player.hp <= player.maxHp//2 and player.hp > 0 and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:gainAnExtraTurn(true)
    player:drawCards(4,self.name)
    room.logic:breakTurn()
  end,
}
local xingpan = fk.CreateTriggerSkill{
  name = "tshu__xingpan",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return  target == player and player:hasSkill(self.name) and player.phase == Player.Play 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|heart,diamond,spade,club",
    }
    room:judge(judge)
    if judge.card.color == Card.Red  then
      local max = 0
      local tar
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not p:isKongcheng() and ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
          if p:getHandcardNum() > max then
            max = p:getHandcardNum()
            tar = p
          end
        end
      end
      if max > 0 and tar then
        if max >= 50 then
          local cards = tar:getCardIds("h")
          if #cards > 0 then
            room:moveCardTo(table.random(cards,max//2),Card.PlayerHand,player,fk.ReasonPrey,self.name)
          end
        else
          local n = math.max(1,max//2)
          local cards = room:askForDiscard(tar,n,n,true,self.name,false,nil,"刑判：请选择将"..n.."张手牌交给 %dest 。::"..player.id,true)
          if #cards > 0 then
            room:moveCardTo(cards,Card.PlayerHand,player,fk.ReasonPrey,self.name)
          end
        end
      end
    elseif judge.card.color == Card.Black  then
      local max = 0
      local tar
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if   ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
          if p.hp > max then
            max = p.hp
            tar = p
          end
        end
      end
      if max > 0 and tar and not tar.dead then
        room:loseHp(tar,1,self.name)
      end
    end
  end,
}
local dianwei = fk.CreateTriggerSkill{
  name = "tshu__dianwei",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return  target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      if p.dead or player.dead then return end
      if #p:getCardIds("e") == 0 and  ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
        room:useVirtualCard("slash", nil, player, {p}, self.name)
      end
    end
    for _, p in ipairs(room.alive_players) do
      if p.dead or player.dead then return end
      if #p:getCardIds("e") > 0 and  ((player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
        local cards = p:getCardIds("e")
        room:moveCardTo(table.random(cards),Card.DiscardPile,player,fk.ReasonDiscard)
      end
    end
  end,
}
yanwang:addSkill(tiemian)
yanwang:addSkill(difu)
yanwang:addSkill(zhennu)
yanwang:addSkill(xingpan)
yanwang:addSkill(dianwei)
yanwang.hidden = true
Fk:loadTranslationTable{
  ["tshugod__yanluowang"] = "阎王",

  ["tshu__tiemian"] = "铁面",
  [":tshu__tiemian"] = "锁定技，当你被红色【杀】指定为目标时，有75%概率令此杀对你无效。",
  ["tshu__difu"] = "地府",
  [":tshu__difu"] = "锁定技，敌方角色的出牌阶段开始时，若其手牌数大于体力值，其弃置超出体力值的手牌数（若其手牌数大于50则改为随机弃置）。",
  ["tshu__zhennu"] = "震怒",
  [":tshu__zhennu"] = "锁定技，每局游戏限一次，当你的体力值降为体力上限的一半及以下时，你摸4张牌并立即执行一个额外的回合。",
  ["tshu__xingpan"] = "刑判",
  [":tshu__xingpan"] = "锁定技，出牌阶段开始时，你进行判定：<br>若为红色，手牌数最多的一名敌方角色将一半手牌交给你（若其手牌数大于50则改为随机选择）；<br>若为黑色，体力最多的一名敌方角色失去一点体力。",
  ["tshu__dianwei"] = "殿威",
  [":tshu__dianwei"] = "锁定技，准备阶段，你视为对所有装备区没牌的敌方角色依次使用一张【杀】，然后随机弃置装备区有牌的敌方角色一张装备区的牌。",
  ["#tshu__xingpan"] = "刑判：请选择将 %arg 张手牌交给 %dest 。",

  ["$tshu__tiemian"] = "铁面无私，秉公执法。",
  ["$tshu__difu"] = "进我地府者，为我所管。",
  ["$tshu__zhennu"] = "岂容汝等..恶鬼放肆。",
  ["$tshu__xingpan"] = "你的罪过，只能用刑场还。",
  ["$tshu__dianwei"] = "殿威。",
  ["~tshugod__yanwang"] = "",

}


local wansha = fk.CreateTriggerSkill{
  name = "tshu__wansha",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing,fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player.room.current and player.room.current == player and player:hasSkill(self) and target ~= player and (event == fk.CardUsing and data.card.name == "peach" and #player.room.logic:getEventsOfScope(GameEvent.UseCard,1, function (e)
      local use = e.data[1]
      return use and use.from == target.id and use.card.name == "peach"
    end, Player.HistoryTurn) == 0
    or  event == fk.EnterDying)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,{target.id})
    if event == fk.CardUsing then
      data.tos = {}
      room:sendLog{ type = "#CardNullifiedBySkill", from = target.id, arg = self.name, arg2 = data.card:toLogString() }
    elseif event == fk.EnterDying then
      player:drawCards(3,self.name)
    end
  end,
}
local guimou = fk.CreateTriggerSkill{
  name = "tshu__guimou",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player.dead and
    data.card:isCommonTrick() and not table.contains(data.card.skillNames,self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local name = Fk:cloneCard(data.card.name)
    name.skillName = self.name
    local to = {}
    for _, ts in ipairs(data.tos) do
      if not room:getPlayerById(ts[1]).dead then
        table.insertIfNeed(to,ts)
      end
    end
    if #to > 0 then
      local use ={
      from = player.id,
      tos = table.random(to,1),
      card = name,
      extraUse = true
      }
      room:useCard(use)
    end
  end,
}
local shanshen = fk.CreateTriggerSkill{
  name = "tshu__shanshen",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and type(player:getMark(self.name)) == "table" and #player:getMark(self.name) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = type(player:getMark(self.name)) == "table" and player:getMark(self.name) or {}
    if #mark > 0 then
      player.maxHp = mark[1]
      room:broadcastProperty(player, "maxHp")
      player.hp = mark[2]
      room:broadcastProperty(player, "hp")
    end
  end,
  refresh_events = {fk.RoundEnd},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self,true)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player,self.name,{player.maxHp,player.hp})
  end,
}
Fk:loadTranslationTable{
  ["tshu__wansha"] = "完杀",
  [":tshu__wansha"] = "锁定技，你的回合内，其他角色每回合使用的第一张【桃】无效，其他角色进入濒死状态时你摸3张牌。",
  ["$tshu__wansha1"] = "哼，无人幸免，无一生还。",
  ["$tshu__wansha2"] = "嘘，你的痛苦，快结束了。",
  ["tshu__guimou"] = "诡谋",
  [":tshu__guimou"] = "锁定技，你使用的普通锦囊牌结算结束后再对其中随机一个目标结算一次。",
  ["$tshu__guimou1"] = "你们之中谁的命更重要，嗯？自己选择吧。",
  ["$tshu__guimou2"] = "这次能活着离开的..",
  ["tshu__shanshen"] = "善身",
  [":tshu__shanshen"] = "锁定技，你的回合开始时，若你持有〖善身〗记录，你将体力上限与体力值调整至〖善身〗的记录值；每轮结束时，记录你当前的体力上限与体力值。",
  ["$tshu__shanshen1"] = "狡兔尚有三窟，而况九尾狐呢？",
  ["$tshu__shanshen2"] = "你们的伎俩，动不了我一根汗毛。",
}

local jienu = fk.CreateActiveSkill{
  name = "tshu__jienu",
  anim_type = "offensive",
  prompt = "使用后，对随机一名敌方角色造成等同其所持技能数点伤害。",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return  player.id < 0 and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return false
  end,
  target_filter = function(self, to_select, selected)
    return false
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local tos = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if ((player.role == "lord" or player.role == "loyalist") and p.role == "rebel" ) or ((player.role == "rebel") and (p.role == "lord" or p.role == "loyalist")) then
        table.insertIfNeed(tos,p.id)
      end
    end
    local to = room:getPlayerById(table.random(tos))
    local n = 0
    for _, s in ipairs(to.player_skills) do
      if s:isPlayerSkill(to) then
        n = n + 1
      end
    end
    room:doIndicate(player.id, {to.id})
      room:damage{
        from = player,
        to = to,
        damage = n,
        damageType = fk.NormalDamage,
        skillName = self.name,
      }
  end,
}

local huoyan = fk.CreateActiveSkill{
  name = "tshu__huoyan",
  anim_type = "offensive",
  prompt = "使用后，随机夺取一名敌方角色一半技能。",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return  player.id < 0 and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return false
  end,
  target_filter = function(self, to_select, selected)
    return false
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local tos = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if ((player.role == "lord" or player.role == "loyalist") and p.role == "rebel" ) or ((player.role == "rebel") and (p.role == "lord" or p.role == "loyalist")) then
        table.insertIfNeed(tos,p.id)
      end
    end
    local to = room:getPlayerById(table.random(tos))
    local skills = {}
    for _, s in ipairs(to.player_skills) do
      if s:isPlayerSkill(to) then
        table.insertIfNeed(skills,s.name)
      end
    end
    room:doIndicate(player.id, {to.id})
    if #skills//2 <= 0 then return end
    local askills = table.random(skills,#skills//2)
    room:handleAddLoseSkills(to,"-"..table.concat(askills,"|-"))
    room:handleAddLoseSkills(player,table.concat(askills,"|"))
  end,
}

local duji = fk.CreateTriggerSkill{
  name = "tshu__duji",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      data.card.type == Card.TypeTrick and data.to ~= player.id
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    if not to:isNude() then
      local cards = to:getCardIds("he")
      room:moveCardTo(table.random(cards),Card.DiscardPile,player,fk.ReasonDiscard,self.name,nil,true,player.id)
    else
      room:damage{
        from = player,
        to = to,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      }
    end
  end,
}
local yinfeng = fk.CreateTriggerSkill{
  name = "tshu__yinfeng",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      data.card.is_damage_card and not data.damageDealt
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1,self.name)
  end,
}
local nimou = fk.CreateTriggerSkill{
  name = "tshu__nimou",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and (event == fk.TurnEnd and player:hasSkill(self) or event == fk.EventAcquireSkill and data == self) and table.contains({"tshugod__jiaxu1","tshugod__jiaxu2"},player.general)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.general == "tshugod__jiaxu1" then
      player.general = "tshugod__jiaxu2"
      room:broadcastProperty(player,"general")
      room:handleAddLoseSkills(player,"-tshu__jienu|-tshu__duji")
      room:handleAddLoseSkills(player,"tshu__huoyan|tshu__yinfeng")
      if event == fk.TurnEnd and player:getMark(self.name.."-round") == 0  then
        room:setPlayerMark(player,self.name.."-round",1)
        player:gainAnExtraTurn(true)
      end
    elseif player.general == "tshugod__jiaxu2" and not (room:getTag("FirstRound") and room:getTag("FirstRound") == true )  then
      player.general = "tshugod__jiaxu1"
      room:broadcastProperty(player,"general")
      room:handleAddLoseSkills(player,"-tshu__huoyan|-tshu__yinfeng")
      room:handleAddLoseSkills(player,"tshu__jienu|tshu__duji")
      if event == fk.TurnEnd and player:getMark(self.name.."-round") == 0 then
        room:setPlayerMark(player,self.name.."-round",1)
        player:gainAnExtraTurn(true)
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["tshu__jienu"] = "竭怒",
  [":tshu__jienu"] = "<font color='blue'>仅人机可用</font>,出牌阶段限一次，你可以对一名随机敌方角色造成等同对方所持技能数点伤害。",
  ["$tshu__jienu"] = "愚蠢的凡人，自相残杀吧！",
  ["tshu__huoyan"] = "惑言",
  [":tshu__huoyan"] = "<font color='blue'>仅人机可用</font>,出牌阶段限一次，你可以夺取一名随机敌方角色的一半技能。",
  ["$tshu__huoyan"] = "我自冷眼看世界，不论天下是与非。",
  ["tshu__duji"] = "毒计",
  [":tshu__duji"] = "锁定技，你的锦囊牌指定其他角色为目标后，若目标有牌则随机弃置其一张牌，否则受到你的一点伤害。",
  ["$tshu__duji1"] = "现在投降，还来得及。",
  ["$tshu__duji2"] = "再见？哈哈，再也不见！",
  ["tshu__yinfeng"] = "隐锋",
  [":tshu__yinfeng"] = "锁定技，你使用的伤害牌结算完成后，若没有造成伤害，你摸一张牌。",
  ["$tshu__yinfeng1"] = "你们的挣扎，不过是苟延残喘罢了。",
  ["$tshu__yinfeng2"] = "南斗掌生，北斗主死。",
  ["tshu__nimou"] = "逆谋",
  [":tshu__nimou"] = "锁定技，若你为贾诩，你的回合结束时，你变换形态并获得对应技能，然后获得一个额外的回合（额外回合每轮限一次）。",
  ["$tshu__nimou1"] = "幕后，才是我的主场。",
  ["$tshu__nimou2"] = "你对我的了解，不过是管中窥豹。",
}

local jiaxu1 = General(extension, "tshugod__jiaxu1","god",25)
jiaxu1.hidden = true
local jiaxu2 = General(extension, "tshugod__jiaxu2","god",25)
jiaxu2.total_hidden = true
jiaxu1:addSkill(wansha)
jiaxu1:addSkill(guimou)
jiaxu1:addSkill(shanshen)
jiaxu1:addSkill(nimou)
jiaxu1:addRelatedSkill(jienu)
jiaxu1:addRelatedSkill(huoyan)
jiaxu1:addRelatedSkill(duji)
jiaxu1:addRelatedSkill(yinfeng)
jiaxu2:addSkill("tshu__wansha")
jiaxu2:addSkill("tshu__guimou")
jiaxu2:addSkill("tshu__shanshen")
jiaxu2:addSkill("tshu__nimou")
jiaxu2:addRelatedSkill("tshu__jienu")
jiaxu2:addRelatedSkill("tshu__huoyan")
jiaxu2:addRelatedSkill("tshu__duji")
jiaxu2:addRelatedSkill("tshu__yinfeng")
jiaxu1:addRelatedSkill("tshu__zhennu")
jiaxu2:addRelatedSkill("tshu__zhennu")
Fk:loadTranslationTable{
  ["tshugod__jiaxu1"] = "贾诩",
  ["~tshugod__jiaxu1"] = "你怎会，逃出生天？",
  ["tshugod__jiaxu2"] = "贾诩",
  ["~tshugod__jiaxu2"] = "终究未能在乱世..善终。"
}
return extension